package com.hugang.annotation;

import org.junit.Test;

import java.lang.annotation.*;

/**
 * 注解的使用
 *
 * @author hg
 * @date 2020/6/18 14:48
 */
@MyAnnotation(value = "hi")
public class AnnotationTest {

    public static void main(String[] args) {

        @SuppressWarnings("unused")
        int num = 0;
    }

    /**
     * 演示@Inherited的继承性
     */
    @Test
    public void test1(){
        Annotation[] annotations = test2.class.getAnnotations();
        for (int i = 0; i < annotations.length; i++) {
            System.out.println(annotations[i]);
        }
    }
}

class test2 extends AnnotationTest{

}

/**
 * 自定义注解
 *
 * @author hg
 * @date 2020/6/18
 */
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
@interface MyAnnotation {
    String value() default "hello";
}
